#ifndef ASTREE_H
#define ASTREE_H

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "hash.h"

#define AST_OP_ADD                           1
#define AST_OP_SUB                           2
#define AST_OP_MUL                           3
#define AST_OP_DIV                           4
#define AST_OP_G                             5
#define AST_OP_L                             6
#define AST_OP_GE                            7
#define AST_OP_LE                            8
#define AST_OP_AND                           9
#define AST_OP_OR                            10
#define AST_OP_REF                           11
#define AST_OP_DEREF                         12
#define AST_OP_EQ                            13
#define AST_OP_NE                            14

#define AST_CMD_ATTR                         15
#define AST_CMD_INPUT                        16
#define AST_CMD_RETURN                       17
#define AST_CMD_OUTPUT                       18
#define AST_CMD_IF                           19
#define AST_CMD_LOOP                         20
#define AST_CMD_FUNCTION_CALL                21
#define AST_CMD_BLOCK                        22

#define AST_DEF_FUNC                         23
#define AST_DEF_UBIQ_VAR                     24
#define AST_DEF_GLOBAL_VAR                   25

#define AST_LST_GBL_DEF                      26
#define AST_LST_PARAM_FUNC_CALL              27
#define AST_LST_LOCAL_VAR                    28
#define AST_LST_INIT_VEC                     29
#define AST_LST_CMD                          30
#define AST_LST_PRINT_VAL                    31
#define AST_LST_PARAM_FUNC                   32

#define AST_LITERAL                          33
#define AST_IDENTIFIER                       34

#define AST_ID_VAL                           35
#define TYPE_BOOL                            36
#define TYPE_WORD                            37
#define TYPE_BYTE                            38

#define AST_PAREN                            39
#define AST_EXPR_FUNCTION_CALL				 40

typedef struct node{
    unsigned int type;
    row *value;
    struct node **chld;
    int lineNumber;
} node;

node* createNode(unsigned int type, row *value, node *s1, node *s2, node *s3, node *s4, int lineNumber);

void printTree(node *root);
void printNode(node *node, int level);
void decompileProgram(node* root, node* father, FILE* fp);
void checkUndefined(node *root, int scope);
void checkDefines(node *root, int scope, int localN);
void checkNature(node *root);
int checkTypes(node *root, node *father);

#endif
